<template>
  <a-modal :open="open" width="640px" title="调整执行" centered destroy-on-close :ok-button-props="{ disabled: !isCompleted }" @ok="onOk" @cancel="onCancel">
    <div class="pl-6 pr-2 pt-1 mb-2 pb-1 border-dashed border-0 border-b-2 bg-black-1">
      <div class="flex items-center justify-between">
        <div class="pl-2">
          {{ formState?.zlxm }}
        </div>
        <div class="text-red-600 font-bold">{{ formState?.sqsj }}</div>
      </div>
    </div>
    <a-form :model="formState" class="form-style-flex" :label-col="{ style: { width: '100px' } }">
      <a-form-item label="原执行人" class="w-1/2">
        <span>{{ formState.zxr || '-' }}</span>
      </a-form-item>
      <a-form-item label="调整执行人" class="w-1/2">
        <selectTable
          v-model:value="formState.zxrName"
          type="护士"
          @select="
            (event) => {
              formState.zxrName = event.empName
              formState.zxrNurseEmpId = event.empId
            }
          "
        />
      </a-form-item>
      <a-form-item label="原执行时间" class="w-1/2">
        <span>{{ formState.zxsj || '-' }}</span>
      </a-form-item>
      <a-form-item label="调整执行时间" class="w-1/2">
        <a-date-picker v-model:value="formState.nurseZxsj" show-time placeholder="请选择" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'

const emit = defineEmits(['update:open', 'success'])
const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})
const formState = ref({})
const rulesState = ref({})
// validateInfos
const { isCompleted, resetFields } = useForm(formState, rulesState)

const onOk = async () => {
  const urlPost = props.rowData.lx ? '/inp/clinicalOrder/modifyAdviceExecInfo' : '/outp/mzys/modifyMzyzb'
  const { code, msg } = await post(urlPost, {
    id: formState.value?.id,
    // zxrName: formState.value.zxrName,
    zxrEmpId: formState.value.zxrNurseEmpId,
    zxsj: formState.value.nurseZxsj
  })
  if (code !== 0) return message.error(msg || '保存失败')
  message.success(msg)
  emit('success')
  onCancel()
}

const onCancel = () => {
  emit('update:open', false)
  resetFields()
}

watch(
  () => props.open,
  (val) => {
    !val && onCancel()
    formState.value = { ...props.rowData }
    !val && onCancel()
    formState.value = { ...props.rowDate }
  }
)
</script>
<style lang="less" scoped>
.bg-black-1 {
  background: rgba(0, 0, 0, 0.1);
}
</style>
